﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace RaSuperGrid.SuperGrid.Converter
{
    class PrefixStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string s = value.ToString();

            int prefixLength;
            if (!int.TryParse(parameter.ToString(), out prefixLength))
                return s;

            if (prefixLength >= s.Length)
                return s;

            return s.Substring(0, prefixLength) + "...";
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
